package com.android.demos.module.main;

import android.location.Location;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.View;

import com.aaron.android.framework.base.ui.actionbar.AppBarSwipeBackActivity;
import com.aaron.android.framework.base.widget.recycleview.OnRecycleViewItemClickListener;
import com.aaron.android.framework.base.widget.recycleview.RecyclerItemDecoration;
import com.aaron.android.framework.base.widget.recycleview.SimpleItemTouchHelperCallback;
import com.android.demos.R;
import com.android.demos.module.appbarstyle.AppBarStyleActivity;
import com.android.demos.module.fresco.FrescoActivity;
import com.android.demos.module.kotlin.AnkoTestActivity;
import com.android.demos.module.kotlin.KotlinTestActivity;
import com.android.demos.module.main.adapter.MainRecyclerAdapter;
import com.android.demos.module.wificonnect.WifiAutoConnectActivity;
import com.soybean.framework.common.LogUtils;

import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import com.soybean.framework.map.amap.AmapGDLocation;
import com.soybean.framework.map.baidumap.BaiduLocation;

/**
 * Created on 15/12/7.
 *
 * @author aaron.huang
 * @version 1.0.0
 */
public class MainActivity extends AppBarSwipeBackActivity {
    public static final int POSITION_APPBAR = 0;
    private static final int POSITION_FRESCO = POSITION_APPBAR + 1;
    private static final int POSISTION_WIFI_CONNECT = POSITION_FRESCO + 1;
    private static final int POSITION_KOTLIN = POSISTION_WIFI_CONNECT + 1;
    private static final int POSITION_KOTLIN_ANKO = POSITION_KOTLIN + 1;
    @BindView(R.id.recycle_view_main)
    RecyclerView mMainRecyclerView;
    private List<String> mRecyclerItemList;
    private View mHeaderView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setSwipeBackEnable(false);
        setTitle(R.string.title_activity_main);
        showHomeUpIcon(0);
        mRecyclerItemList = Arrays.asList(getResources().getStringArray(R.array.main_item_title));
        initViews();
    }

    private void initViews() {
        mMainRecyclerView = (RecyclerView) findViewById(R.id.recycle_view_main);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        mMainRecyclerView.addItemDecoration(new RecyclerItemDecoration(this, LinearLayoutManager.VERTICAL,
                R.drawable.main_recycler_divider));
        mMainRecyclerView.setLayoutManager(layoutManager);
        MainRecyclerAdapter mainRecyclerAdapter = new MainRecyclerAdapter(this);
        mainRecyclerAdapter.setData(mRecyclerItemList);
        mMainRecyclerView.setAdapter(mainRecyclerAdapter);
        mainRecyclerAdapter.setOnRecycleViewItemClickListener(new OnRecycleViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (position == POSITION_APPBAR) {
                    startActivity(AppBarStyleActivity.class);
                } else if (position == POSITION_FRESCO) {
                    startActivity(FrescoActivity.class);
                } else if (position == POSISTION_WIFI_CONNECT) {
                    startActivity(WifiAutoConnectActivity.class);
                } else if (position == POSITION_KOTLIN) {
                    startActivity(KotlinTestActivity.class);
                } else if (position == POSITION_KOTLIN_ANKO) {
                    startActivity(AnkoTestActivity.class);
                }
            }

            @Override
            public boolean onItemLongClick(View view, int position) {
                LogUtils.d(TAG, "long click position: " + position);
                return true;
            }
        });
        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new SimpleItemTouchHelperCallback(mainRecyclerAdapter));
        itemTouchHelper.attachToRecyclerView(mMainRecyclerView);
    }

    private void addHeaderFooters(final MainRecyclerAdapter mainRecyclerAdapter) {
        mHeaderView = getLayoutInflater().inflate(R.layout.layout_main_header, mMainRecyclerView, false);
        mainRecyclerAdapter.addHeaderView(mHeaderView);
        mHeaderView.setClickable(true);
        mHeaderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mainRecyclerAdapter.removeHeaderView(mHeaderView);
            }
        });
        View footerView1 = getLayoutInflater().inflate(R.layout.layout_main_footer, mMainRecyclerView, false);
        mainRecyclerAdapter.addFooterView(footerView1);
        mainRecyclerAdapter.addFooterView(null);
        View footerView2 = getLayoutInflater().inflate(R.layout.layout_main_header, mMainRecyclerView, false);
        mainRecyclerAdapter.addFooterView(footerView2);
        footerView1.setClickable(true);
        footerView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }

}
